package com.kotlin.zds.activity

import android.view.LayoutInflater
import android.view.ViewGroup
import coil.load
import com.alibaba.android.arouter.facade.annotation.Route
import com.kotlin.zds.R
import com.kotlin.zds.arouter.Routes
import com.kotlin.zds.base.BaseActivity
import com.kotlin.zds.databinding.ActivityRvgvBinding
import com.kotlin.zds.databinding.ItemRvgViewBinding
import com.xuexiang.xui.utils.StatusBarUtils
import com.zds.support.adapter.CommonRecyclerAdapter
import com.zds.support.api.resp.RecordMsg

/**
 * Author: zds
 * Date: 2022/11/6 20:13
 * Description:
 * Version: v1.0
 */
@Route(path = Routes.PATH_RVGV)
class RvGvActivity: BaseActivity() {
    var data = ArrayList<RecordMsg>()
    val adapter by lazy {
        object: CommonRecyclerAdapter<ItemRvgViewBinding,RecordMsg>(this@RvGvActivity,data){
            override fun getViewBinding(parent: ViewGroup?): ItemRvgViewBinding {
                return ItemRvgViewBinding.inflate(mLayoutInflater,parent,false)
            }

            override fun convert(viewBinding: ItemRvgViewBinding, data: RecordMsg) {
                with(viewBinding){
                    tvMainItemText.text = data.title
                    //图片加载
                    ivMainItemImg.load(data.url){
                        error( R.drawable.icon_my_defaut)
                    }
                }
            }

        }
    }
    val viewBinding by lazy {
        ActivityRvgvBinding.inflate(LayoutInflater.from(mActivity))
    }

    override fun onSetContentView() {
        StatusBarUtils.initStatusBarStyle(this,false)
        setContentView(viewBinding.root)
    }

    override fun initView() {
        viewBinding.run {
            rvMsg.adapter = adapter
        }

    }

    override fun initData() {
        data.add(RecordMsg("1","https://img2.doubanio.com/view/photo/s_ratio_poster/public/p2882549201.webp"))
        data.add(RecordMsg("2","https://img2.doubanio.com/view/photo/s_ratio_poster/public/p2545472803.webp"))
        data.add(RecordMsg("3","https://img2.doubanio.com/view/photo/s_ratio_poster/public/p2545472803.webp"))
        data.add(RecordMsg("4","https://img2.doubanio.com/view/photo/s_ratio_poster/public/p2545472803.webp"))
        data.add(RecordMsg("5","https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2567998580.webp"))
        data.add(RecordMsg("6","https://img3.doubanio.com/view/photo/s_ratio_poster/public/p2567998580.webp"))
        adapter.notifyDataSetChanged()
    }
}